using System.ComponentModel;
using System.Xml;

namespace ArcEngine.Resources
{
	/// <summary>
	/// A transformer en Interface...
	/// </summary>
	public abstract class ResourceBase
	{
		/// <summary>
		/// Name of the resource
		/// </summary>
		[Browsable(false)]
		public string Name
		{
			get { return name; }
		}
		string name;

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="name">Name of the resource</param>
		public ResourceBase(string name)
		{
			this.name = name;
			//loaded = false;
		}


		#region Resource locking
		/// <summary>
		/// 
		/// </summary>
		public void LockResource()
		{
			lockCount++;
		}

		/// <summary>
		/// 
		/// </summary>
		public void UnlockResource()
		{
			lockCount--;
		}


		/// <summary>
		/// Returns the number of time this resource is locked
		/// </summary>
		[Browsable(false)]
		public int LockCount
		{
			get { return lockCount; }
		}
		private int lockCount;

		#endregion


		#region IO routines
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public virtual bool Save(XmlWriter xml)
		{

			return false;

		}



		/// <summary>
		/// 
		/// </summary>
		public virtual bool Load(XmlNode xml)
		{
			if (xml.NodeType == XmlNodeType.Comment)
			{
				comments = xml.InnerText;
				return true;
			}

			switch (xml.Name.ToLower())
			{
				default:
				{
					
				}
				break;
			}

			return true;

		}


		/// <summary>
		/// 
		/// </summary>
		/// <param name="xml"></param>
		protected void SaveComment(XmlWriter xml)
		{
			if (!string.IsNullOrEmpty(comments))
			{
				xml.WriteComment(comments);
			}

		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="xml"></param>
		protected void LoadComment(XmlNode xml)
		{
			comments = xml.Value;
		}


		#endregion


		#region Properties


		/// <summary>
		/// Gets / Sets comments on the resource
		/// </summary>
		public string Comments
		{
			get
			{
				return comments;
			}

			set
			{
				comments = value;
			}

		}
		string comments;

		#endregion

	}
}

